def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True
input_str = input("Введите три слова, разделенных пробелом: ")
words = input_str.split()
if len(words) != 3:
    print("Wrong input")
else:
    num_dict = {
        "zero": 0,
        "one": 1,
        "two": 2,
        "three": 3,
        "four": 4,
        "five": 5,
        "six": 6,
        "seven": 7,
        "eight": 8,
        "nine": 9
    }
    num = num_dict[words[0]] * 100 + num_dict[words[1]] * 10 + num_dict[words[2]]
    diff = 0
    while True:
        if is_prime(num + diff):
            print(num + diff)
            break
        elif is_prime(num - diff):
            print(num - diff)
            break
        diff += 1

